/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

/**
 *
 * @author Morten J, Morten B & Jonas
 */
public class PrintPage extends javax.swing.JPanel implements Printable {

    /**
     * Creates new form PrintPage
     *
     * @param text
     */
    public PrintPage(String text) {
	initComponents();
	jText.setText(text);
	jText.setFocusable(false);
	jText.setCaretPosition(0);
    }

    @Override
    public int print(Graphics g, PageFormat pageFormat, int page) throws PrinterException {
	int printRes;
	if (page > 0) {
	    printRes = NO_SUCH_PAGE;
	} else {
	    Graphics2D g2d = (Graphics2D) g;
	    double x = pageFormat.getImageableX();
	    double y = pageFormat.getImageableY();
	    g2d.translate(x, y);
	    printRes = PAGE_EXISTS;
	}
	return printRes;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPan = new javax.swing.JPanel();
        jPrintLogo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jText = new javax.swing.JTextArea();

        jPrintLogo.setBackground(java.awt.Color.darkGray);
        jPrintLogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPrintLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/museumsyd.jpg"))); // NOI18N

        jText.setEditable(false);
        jText.setColumns(20);
        jText.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
        jText.setForeground(new java.awt.Color(25, 25, 25));
        jText.setRows(5);
        jScrollPane1.setViewportView(jText);

        javax.swing.GroupLayout jPanLayout = new javax.swing.GroupLayout(jPan);
        jPan.setLayout(jPanLayout);
        jPanLayout.setHorizontalGroup(
            jPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(jPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPrintLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE))
                .addGap(0, 0, 0))
        );
        jPanLayout.setVerticalGroup(
            jPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jPrintLogo)
                .addGap(0, 0, 0)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPan, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPan, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPan;
    private javax.swing.JLabel jPrintLogo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jText;
    // End of variables declaration//GEN-END:variables
}
